package com.xw.base.entity.base;

import com.xw.base.entity.exception.IException;
import lombok.Data;

@Data
public class JsonResult<T> {

    private int code;
    private String message;
    private String request_id;
    private T data;

    public JsonResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public JsonResult(int code, String message, String request_id) {
        this.code = code;
        this.message = message;
        this.request_id = request_id;
    }

    public JsonResult(int code, String message, String request_id, T data) {
        this.code = code;
        this.message = message;
        this.request_id = request_id;
        this.data = data;
    }

    public JsonResult(int status, IException i, T data) {
        this.code = code;
        this.message = i.getErrMessage();
        this.data = data;
    }

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<>(0, "成功", "", data);
    }

}
